#include<iostream>

#include<stdio.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <sys/mman.h>

#include <fcntl.h>

#include<string.h>

#include<unistd.h>

using namespace std;

int main()
{
    int fd = open("log.txt", O_RDWR);

    if(fd < 0)
    {
        perror("open");
        exit(1);
    }

    struct stat st;
    if (fstat(fd, &st) < 0) {
        perror("fstat");
        close(fd);
        exit(1);
    }

    size_t file_size = st.st_size;
    
    void *addr = mmap(nullptr, file_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

    close(fd);

    memcpy(addr, "HELLO", 5);

    munmap(addr, file_size);

    return 0;
}